#include "newddsdevicedialog.h"
#include "ui_newddsdevicedialog.h"
#include "projdata/deviceinfo.h"
#include "qsoftcore.h"
#include "qprojectcore.h"
#include "devicepluginloader.h"
#include <IDevicePlugin.h>
NewDdsDeviceDialog::NewDdsDeviceDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::NewDdsDeviceDialog)
{
    ui->setupUi(this);
}

NewDdsDeviceDialog::~NewDdsDeviceDialog()
{
    delete ui;
}
void NewDdsDeviceDialog::load(const QString &szName){
}

void NewDdsDeviceDialog::save(const QString &szName){
    DeviceInfo &deviceInfo = QSoftCore::getCore()->getProjectCore()->m_deviceInfo;
    DeviceInfoObject *pObj = deviceInfo.getObjectByName(szName);

    if(pObj == NULL) {
        pObj = deviceInfo.newObject();
        if(pObj == NULL) {
            return;
        }
    }

    pObj->m_deviceType = "DDS";
    pObj->m_name = ui->deviceName->text();
    pObj->m_deviceName = "";
    pObj->m_frameLen = 0;
    pObj->m_protocol = "dds";
    pObj->m_link = "";
    pObj->m_stateVar = 0;
    pObj->m_frameTimePeriod = 0;
    pObj->m_ctrlVar = 0;
    pObj->m_dynamicOptimization = 0;
    pObj->m_remotePort = 0;

    DdsDevice ddsDev;
    ddsDev.m_ipAddress = "";
    ddsDev.m_port = 0;
    ddsDev.m_ipAddress1 = "";
    ddsDev.m_port1 = 0;

    pObj->m_portParameters = ddsDev.toString();

    QString pluginName = pObj->m_deviceName;
    IDevicePlugin *pDevPluginObj = DevicePluginLoader::getInstance()->getPluginObject(pluginName);
    if (pDevPluginObj) {
        pDevPluginObj->writeProperties(pObj->m_properties, m_properties);
    }
}

QString NewDdsDeviceDialog::GetDeviceName() const
{
    return {};

}
QString NewDdsDeviceDialog::pluginName() const
{
    return {};
}
// 更新PropertyEditor数据
void NewDdsDeviceDialog::updatePropertyEditor(){

}
